﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Jodell.Transport.Modbus
{
    public static class Extensions
    {
        public static void AddReverse(this IList<byte> datas, UInt16 param)
        {
            var buf = BitConverter.GetBytes(param);
            Array.Reverse(buf);
            foreach (var d in buf)
            {
                datas.Add(d);
            }
        }
        public static void Add(this IList<byte> datas, UInt16 param)
        {
            var buf = BitConverter.GetBytes(param);
            foreach (var d in buf)
            {
                datas.Add(d);
            }
        }

        public static string _ToString(this IEnumerable<byte> datas)
        {
            StringBuilder sb = new StringBuilder();
            foreach (var d in datas)
            {
                sb.Append(d.ToString("X2"));
                sb.Append(' ');
            }
            return sb.ToString();
        }
    }
}
